require 'basic.pl';
my $doctxt = "doctors.txt";
my $typtxt = "types.txt";
#gets a list of types
sub get_types {
	open(TYPES, $typtxt);
	my @types = <TYPES>;
	chomp @types;
	return @types;
}
#checks if a str is a listed type
sub is_type {
	my $type = $_[0];
	foreach my $t (get_types()){
		if ($type eq $t){
			return 1;
			last;
		}
	}
	return 0;
}
#get attributes of a doctor given name
sub get_doctor {
	my $doctor = $_[0];
	open(DOCS, $doctxt);
	while (<DOCS>){
		my @vals = tokenize($_);
		if ($vals[0] eq $doctor){
			close(DOCS);
			return @vals;
		}
	}
	return ();
}
#get the type of doctor given name
sub get_type_of_doctor {
	my @vals = get_doctor($_[0]);
	return $vals[1];
}
#get all the names of doctors of a given type
sub get_doctors_type {
	my $type = $_[0];
	my @docs = get_doctors();
	my @type_docs = ();
	foreach my $doc (@docs){
		my @vals = get_doctor($doc);
		if ($vals[1] eq $type){
			push @type_docs, $vals[0];
		} 
	}
	chomp @type_docs;
	return @type_docs;
}
#get all doctors' names
sub get_doctors {
	open(DB, $doctxt);
	my @docs = ();
	while(<DB>){
		my @vals = tokenize($_);
		push @docs, $vals[0];
	}
	close(DB);
	chomp @docs;
	return @docs;
}
1;
